<template>
  <div>
    <div>
      <el-form :inline="true" :model="PIRForm" class="demo-form-inline">
        <el-form-item label="订单编码" prop="orderNumber">
          <el-input v-model="PIRForm.orderNumber" placeholder="请输入内容" size="small"></el-input>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="PIRForm.productName" placeholder="请输入内容" size="small"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search" size="small">搜索</el-button>
          <el-button @click="resetSearchForm()" size="small">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="loading" :data="tableList" border style="width: 100%"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50">
      </el-table-column>
      <el-table-column prop="orderNumber" label="检测订单编码">
      </el-table-column>
      <el-table-column prop="result" label="检测结果">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.result == 0" type="danger">不合格</el-tag>
          <el-tag v-if="scope.row.result == 1" type="success">合格</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="productCode" label="产品编码">
      </el-table-column>
      <el-table-column prop="productName" label="产品名称">
      </el-table-column>
      <el-table-column prop="productUnit" label="产品单位">
      </el-table-column>
      <el-table-column prop="quantity" label="检测数量">
      </el-table-column>
      <el-table-column prop="inspectionRemark" label="备注">
      </el-table-column>
      <el-table-column prop="operationTime" label="检测时间">
      </el-table-column>
      <el-table-column prop="empName" label="经办人">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="DialogOpen(scope.row)">添加备注</el-button>
          <el-button type="text" size="small" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="totalPage">
    </el-pagination>

    <el-dialog title="备注" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="备注">
          <el-input v-model="form.inspectionRemark" autocomplete="off" type="textarea"
            :autosize="{ minRows: 2, maxRows: 6 }"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitType()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getAllList ,updateRemark,delById} from '@/api/pir'
export default {
  name: '',
  data() {
    return {
      loading: false,
      currentPage: 1,
      pageNum: 1,
      pageSize: 5,
      totalPage: 0,
      tableList: [],
      ids: [],
      dialogFormVisible: false,
      form:{
        id:'',
        inspectionRemark:''
      },
      PIRForm:{
        orderNumber:'',
        productName:''
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val
      this.fetchDate()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.fetchDate()
    },
    handleSelectionChange(val) {
      this.ids = []
      for (var i = 0; i < val.length; i++) {
        this.ids.push(val[i].id)
      }
    },
    fetchDate() {
      this.loading = true
      getAllList({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        orderNumber: this.PIRForm.orderNumber,
        productName: this.PIRForm.productName
      }).then(res => {
        if (res.code == 200) {
          this.tableList = res.data.list
          this.totalPage = res.data.total
          this.loading = false
        }
      })
    },
    DialogOpen(row){
      this.form = row
      this.dialogFormVisible = true
    },
    submitType(){
      updateRemark({
        id: this.form.id,
        inspectionRemark: this.form.inspectionRemark
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            type: 'success',
          })
          this.dialogFormVisible = false
        }
      })
    },
    search(){
      this.fetchDate()
    },
    resetSearchForm(){
      this.PIRForm = {}
      this.fetchDate()
    },
    del(id){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delById({
          id: id
        }).then(res => {
          if (res.code == 200) {
            this.$message({
              message: res.msg || '删除成功',
              type: 'success',
            })
            this.fetchDate()

          }
        })
      })

    }
    

  },
  created() {
    this.fetchDate()
  }
}
</script>
<style scoped></style>